<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>芯片管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../js/layui/css/layui.css" media="all">
</head>
<body>
<blockquote class="layui-elem-quote quoteBox mod_default_box">
    <div class="layui-form">
        <div class="layui-inline">
            <div class="layui-input-inline" >
                <input type="text" id="xuliehao" name="xuliehao" placeholder="请输入关键字" autocomplete="off" class="layui-input" />
            </div>
            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="search-card-submit">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <select name="city" lay-verify="" lay-filter="status" id="status" lay-search>
                    <option value="">选择状态</option>
                </select>
            </div>
        </div>
    </div>
</blockquote>
<div class="layui-card-body">
    <table class="layui-hide" id="t" lay-filter="t"></table>
</div>
</body>
<script type="text/html" id="caozuo">
    <a class="layui-btn  layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑芯片状态</a>
    <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="chongzhi">重置密码</a>-->
</script>
<script src="../../js/layui/layui.js"></script>
<script src="../../js/layui/layui.all.js"></script>
<script src="../../js/config.js"></script>
<script src="../../js/token.js"></script>
<script>
    layui.use(['table'], function() {
        var $ = layui.$;
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var xuliehao = "";
        var status = "";
        table.render({
            elem: '#t',
            id: 'tt',
            toolbar: '#tb',
            url: HOST+'card/getCard',
            cols: [
                [{
                    field: 'id',
                    title: '序号',
                    type: 'numbers',
                    align: 'center' ,
                    fixed: "left"
                },
                    {
                        field: 'ygBh',
                        title: '编号',
                        width : 140,
                        align: 'center' ,
                        fixed: "left"
                    },
                    {
                        field: 'ygName',
                        title: '姓名',
                        width: 120,
                        align: 'center'
                    },
                    {
                        field: 'ygPhone',
                        title: '联系方式',
                        width : 150,
                        align: 'center'
                    },
                    /*{
                        field: 'ygSfz',
                        title: '证件号',
                        width : 200,
                        align: 'center'
                    },*/
                    {
                        field: 'xuliehao',
                        title: '芯片序列号',
                        width : 120,
                        align: 'center'
                    },
                    {
                        field: 'statusName',
                        title: '芯片状态',
                        width : 110,
                        align: 'center'
                    },
                    {
                        field: 'luRuCreateTime',
                        title: '芯片录入时间',
                        width : 160,
                        align: 'center'
                    },
                    {
                        field: 'sxTime',
                        title: '失效时间',
                        width: 160,
                        align: 'center'
                    },
                    {
                        title: '操作',
                        width : 160,
                        align: 'center',
                        toolbar: '#caozuo',
                        fixed: 'right'
                    }]
            ], page: true
            ,page: {
                curr: layui.data("card_page").index
            },
            done: (res, curr, count) => {
                layui.data("card_page", {
                    key: 'index',
                    value: curr
                });
            }
        });

        //表操作  监听操作
        table.on('tool(t)', function (obj) {
            var data=obj.data;
            var event = obj.event;
            if (event === 'edit') {
                layer.open({
                    type:2
                    ,title:"修改芯片信息"
                    ,skin:'layui-layer-molv'
                    ,area: ['95%', '95%']
                    ,content:(encodeURI("upd_card.html?xuliehao="+data.xuliehao+"&statusName="+data.statusName+"&luru_createtime="+data.luRuCreateTime+"&id="+data.id+"&statusCode="+data.statusCode
                        +"&ygName="+data.ygName+"&ygBh="+data.ygBh+"&ygPhone="+data.ygPhone+"&ygSfz="+data.ygSfz+"&sxTime="+data.sxTime))  //js获取url参数
                });
            }
        });

        table.on('toolbar(t)', function (obj) {
            var data = obj.data;
            // console.log(data);
            if (obj.event === 'add') {
                var index = layer.open({
                    type: 2,
                    area: ['100%', '100%'],
                    content: 'add_card.html', //这里content是一个普通的String
                    end: function(){
                        location.reload();
                    }
                });
                layer.full(index);
            }
        });
        //搜索操作
        form.on('submit(search-card-submit)', function (data) {
            table.reload('tt', {
                where: {"xuliehao": data.field.xuliehao,"status":status}
                , page: {
                    curr: 1
                }
            });
            return false;
        });
        // 动态添加状态
        $.ajax({
            url:HOST+"card/getCardStatusDic" ,
            success:function(res){
                if(res.code == 0) {
                    for(var i in res.data) {
                        $("#status").append("<option value='"+res.data[i].code+"'>"+res.data[i].name+"</option>")
                    }
                    form.render()
                }
            }
        });
        // 搜索状态
        form.on('select(status)', function(data){
            status = data.value
            xuliehao = $("#xuliehao").val()
            table.reload('tt', {
                where: { "xuliehao": xuliehao,"status":status}
                , page: {
                    curr: 1
                }
            });
        });
    })
</script>
</html>